package pers.zyl.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import pers.zyl.product.config.GoCondition;
import pers.zyl.product.facade.FundFacade;
import pers.zyl.product.servuce.ProductService;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@RestController
public class ProductController {
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private FundFacade fundFacade;

    @Autowired(required = false)
    @GoCondition
    private ProductService productService;

    @PostMapping("/purchase/{userId}/{productId}/{amount}")
    public String purChaseProduct(
            @PathVariable("userId") Long userId,
            @PathVariable("productId") Long productId,
            @PathVariable("amount") BigDecimal amount

    ) {

        return fundFacade.getFundMessage(userId, amount);
    }

    @PostMapping("/own")
    public String own() {
        String url = "http://PRODUCT/test";
        return restTemplate.postForObject(url,   null, String.class);
    }

    @PostMapping("/test")
    public String test() {
        return "test";
    }



}
